Technical Q&ATB 65 - Progress Indicators and
|
sixteenBitValue = (0x00007FFF & value) | ((0x80000000 & value) >> 16); |
This raises a number of related questions:
How can I tell whether a control definition supports 32-bit values?
There is no general way of doing this. The only way to know whether it is safe to use 32-bit values with a particular control definition is to ask its author.
Which standard control definitions support 32-bit values?
In Mac OS 8.5 through 9.0, only the scroll bar (CDEFs 1 and 24) and slider (CDEF 3) control definitions support 32-bit values.
How do I support 32-bit values in my control definition?
The first step is to ensure that you call the 32-bit accessors when you need to access the control's value, minimum, and maximum. Obviously, you should do this only if these accessors are available (Mac OS 8.5 or later, or Carbon). Beyond that, it's a simple matter of checking that your implementation handles these large values.
How do I work around this problem for the progress bar control?
If the upper limit of your progress is beyond 32767, the simplest workaround is to set the control's maximum to 32767 and then scale the control value, as shown below. It is often convenient to use floating point arithmetic to avoid overflows.
scaledValue = (unscaledValue / unscaledLimit) * 32767;
Isn't this supposed to be easier?
Don't ask me, I'm just a networking guy. [2409633]